<template>
  <div>
    <div>
      <el-upload
        ref="upload"
        action="fakeaction"
        :show-file-list="false"
        accept=".xlsx,.xls,.XLSX,.XLS"
        :http-request="uploadSectionFile"
        :limit="1"
      >
        <el-button type="primary">导入excel文件</el-button>
      </el-upload>
    </div>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          解析为数字,多个用','隔开
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="genNumber">
          </el-input>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          sheet名字
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="sheetName">
          </el-input>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          行开始
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="rowTop">
          </el-input>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          行结束
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="rowEnd">
          </el-input>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          列开始
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="colBegin">
          </el-input>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" class="row-bg" :gutter="20">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          列结束
        </div>
      </el-col>
      <el-col :span="18">
        <div class="grid-content bg-purple-light">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="colEnd">
          </el-input>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import tableCodeGenUtils from "@/utils/tableCodeGenUtils";
import {genNumber} from "@/views/utils/views/excel2Table/common";

export default {
  name: 'ConfigPage',
  data(){
    return{
      genNumber,
      sheetName: 'Sheet1',
      rowTop: '1',
      rowEnd: '1',
      colBegin: 'A',
      colEnd: 'B',
    }
  },
  methods:{
    async uploadSectionFile(options) {
      const file = options.file;
      const tableCodeGenItems = await tableCodeGenUtils.excelToTableHead(file, this.sheetName, this.rowTop, this.rowEnd, this.colBegin, this.colEnd);
      tableCodeGenUtils.initPropCount()
      this.$emit('success',tableCodeGenItems)
      this.$message.success('解析完成')
      this.$nextTick(() => {
        this.$refs.upload.clearFiles()
      })
    },
  }
}
</script>
<style scoped lang="scss">
.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
  text-align: right;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
